home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Tools & Apps / Networking & Communications / TCPTool / dnr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-09-14  |  3.5 KB  |  172 lines  |  [TEXT/MPS ]

  1. /*     DNR.c - DNR library for MPW
  2.  
  3.     (c) Copyright 1988 by Apple Computer.  All rights reserved
  4.     
  5. */
  6.  
  7. #define MPW3.0 true
  8.  
  9. #include <OSUtils.h>
  10. #include <Errors.h>
  11. #include <Files.h>
  12. #include <Resources.h>
  13. #ifdef MPW3.0
  14. #include <Memory.h>
  15. #endif
  16.  
  17. #define OPENRESOLVER    1
  18. #define CLOSERESOLVER    2
  19. #define STRTOADDR        3
  20. #define    ADDRTOSTR        4
  21. #define    ENUMCACHE        5
  22. #define ADDRTONAME        6
  23.  
  24. Handle codeHndl = nil;
  25.  
  26. typedef OSErr (*OSErrProcPtr)();
  27. OSErrProcPtr dnr = nil;
  28.  
  29.  
  30. /* OpenOurRF is called to open the MacTCP driver resources */
  31.  
  32. short OpenOurRF() {
  33.     SysEnvRec info;
  34.     HParamBlockRec fi;
  35.     Str255 filename;
  36.     
  37.     SysEnvirons(1, &info);
  38.     
  39.     fi.fileParam.ioCompletion    = nil;
  40.     fi.fileParam.ioNamePtr        = &filename;
  41.     fi.fileParam.ioVRefNum        = info.sysVRefNum;
  42.     fi.fileParam.ioDirID        = 0;
  43.     fi.fileParam.ioFDirIndex    = 1;
  44.     
  45.     while (PBHGetFInfo(&fi, false) == noErr) {
  46.         /* scan system folder for driver resource files of specific type & creator */
  47.         if (fi.fileParam.ioFlFndrInfo.fdType == 'cdev' && fi.fileParam.ioFlFndrInfo.fdCreator == 'mtcp') {
  48.             /* found the MacTCP driver file */
  49.             SetVol(0,info.sysVRefNum);
  50.             return(OpenResFile(&filename));
  51.         }
  52.         
  53.         /* check next file in system folder */
  54.         fi.fileParam.ioFDirIndex++;
  55.         fi.fileParam.ioDirID = 0;
  56.     }
  57.     return(-1);
  58. }
  59.  
  60.  
  61.  
  62. OSErr OpenResolver(fileName)
  63. char *fileName;
  64. {
  65.     short refnum;
  66.     OSErr rc;
  67.     
  68.     if (dnr != nil)
  69.         /* resolver already loaded in */
  70.         return(noErr);
  71.         
  72.     /* open the MacTCP driver to get DNR resources. Search for it based on
  73.        creator & type rather than simply file name */    
  74.     refnum = OpenOurRF();
  75.  
  76.     /* ignore failures since the resource may have been installed in the 
  77.        System file if running on a Mac 512Ke */
  78.        
  79.     /* load in the DNR resource package */
  80.     codeHndl = GetIndResource('dnrp', 1);
  81.     if (codeHndl == nil) {
  82.         /* can't open DNR */
  83.         return(ResError());
  84.         }
  85.     
  86.     DetachResource(codeHndl);
  87.     if (refnum != -1) {
  88.         CloseResFile(refnum);
  89.         }
  90.         
  91.     /* lock the DNR resource since it cannot be reloated while opened */
  92.     HLock(codeHndl);
  93.     dnr = (OSErrProcPtr) *codeHndl;
  94.     
  95.     /* call open resolver */
  96.     rc = (*dnr)(OPENRESOLVER, fileName);
  97.     if (rc != noErr) {
  98.         /* problem with open resolver, flush it */
  99.         HUnlock(codeHndl);
  100.         DisposHandle(codeHndl);
  101.         dnr = nil;
  102.         }
  103.     return(rc);
  104.     }
  105.  
  106.  
  107. OSErr CloseResolver()
  108. {
  109.     if (dnr == nil)
  110.         /* resolver not loaded error */
  111.         return(notOpenErr);
  112.         
  113.     /* call close resolver */
  114.     (void) (*dnr)(CLOSERESOLVER);
  115.  
  116.     /* release the DNR resource package */
  117.     HUnlock(codeHndl);
  118.     DisposHandle(codeHndl);
  119.     dnr = nil;
  120.     return(noErr);
  121.     }
  122.  
  123. OSErr StrToAddr(hostName, rtnStruct, resultproc, userDataPtr)
  124. char *hostName;
  125. struct hostInfo *rtnStruct;
  126. long resultproc;
  127. char *userDataPtr;
  128. {
  129.     if (dnr == nil)
  130.         /* resolver not loaded error */
  131.         return(notOpenErr);
  132.         
  133.     return((*dnr)(STRTOADDR, hostName, rtnStruct, resultproc, userDataPtr));
  134.     }
  135.     
  136. OSErr AddrToStr(addr, addrStr)
  137. unsigned long addr;
  138. char *addrStr;                                    
  139. {
  140.     if (dnr == nil)
  141.         /* resolver not loaded error */
  142.         return(notOpenErr);
  143.         
  144.     (*dnr)(ADDRTOSTR, addr, addrStr);
  145.     return(noErr);
  146.     }
  147.     
  148. OSErr EnumCache(resultproc, userDataPtr)
  149. long resultproc;
  150. char *userDataPtr;
  151. {
  152.     if (dnr == nil)
  153.         /* resolver not loaded error */
  154.         return(notOpenErr);
  155.         
  156.     return((*dnr)(ENUMCACHE, resultproc, userDataPtr));
  157.     }
  158.     
  159.     
  160. OSErr AddrToName(addr, rtnStruct, resultproc, userDataPtr)
  161. unsigned long addr;
  162. struct hostInfo *rtnStruct;
  163. long resultproc;
  164. char *userDataPtr;                                    
  165. {
  166.     if (dnr == nil)
  167.         /* resolver not loaded error */
  168.         return(notOpenErr);
  169.         
  170.     return((*dnr)(ADDRTONAME, addr, rtnStruct, resultproc, userDataPtr));
  171.     }
  172.